<template>
  <div>
    <div>
      <div style="display: flex">
        <div style="padding-right: 10px">
          <el-input
            placeholder="请输入工号进行搜索，可以直接回车搜索..."
            prefix-icon="el-icon-search"
            clearable
            @clear="initRecords"
            style="width: 350px; margin-right: 10px"
            v-model="searchValue.keyword"
            @keydown.enter.native="initRecords"
          ></el-input>

          <el-button type="primary" @click="showDateSearchView =! showDateSearchView">
            <i
              :class="
                showDateSearchView
                  ? 'fa fa-angle-double-up'
                  : 'fa fa-angle-double-down'
              "
              aria-hidden="true"
            ></i>
            选择日期
          </el-button>
          <el-button
            icon="el-icon-search"
            type="primary"
            @click="initRecords"
          >
            <!--                        @click="initRecords"-->
            搜索
          </el-button>
        </div>

        <div>
          <transition name="slide-fade">
            <div v-show="showDateSearchView">
              <el-date-picker
                v-model="date"
                type="monthrange"
                range-separator="至"
                value-format="yyyy-MM"
                start-placeholder="开始月份"
                end-placeholder="结束月份"
              >
              </el-date-picker>
            </div>
          </transition>
        </div>
      </div>
    </div>
    <div style="margin-top: 10px">
      <el-table
        :data="records"
        stripe
        border
        v-loading="loading"
        element-loading-text="正在加载..."
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(0, 0, 0, 0.8)"
        style="width: 100%"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column
          prop="employee.workID"
          fixed
          align="left"
          label="工号"
          width="80"
        >
        </el-table-column>
        <el-table-column
          prop="employee.name"
          fixed
          label="姓名"
          align="left"
          width="80"
        >
        </el-table-column>
        <el-table-column prop="time" label="时间" align="left" width="100">
        </el-table-column>
        <el-table-column
          prop="normalSign"
          label="正常打卡次数"
          align="left"
          width="100"
        >
        </el-table-column>
        <el-table-column
          prop="miss"
          label="未打卡次数"
          align="left"
          width="100"
        >
        </el-table-column>
        <el-table-column
          prop="lateInSign"
          label="迟到次数"
          align="left"
          width="100"
        >
        </el-table-column>
        <el-table-column
          prop="earlyOutSign"
          label="早退次数"
          align="left"
          width="100"
        >
        </el-table-column>

        <el-table-column
          prop="employee.department.name"
          label="所属部门"
          width="200"
          align="left"
        ></el-table-column>
        <el-table-column label="对应账套" align="center">
          <template slot-scope="scope">
            <el-tooltip placement="right" v-if="scope.row.employee.salary">
              <div slot="content">
                <table>
                  <tr>
                    <td>基本工资</td>
                    <td>{{ scope.row.employee.salary.basicSalary }}</td>
                  </tr>
                  <tr>
                    <td>交通补助</td>
                    <td>{{ scope.row.employee.salary.trafficSalary }}</td>
                  </tr>
                  <tr>
                    <td>午餐补助</td>
                    <td>{{ scope.row.employee.salary.lunchSalary }}</td>
                  </tr>
                  <tr>
                    <td>奖金</td>
                    <td>{{ scope.row.employee.salary.bonus }}</td>
                  </tr>
                  <tr>
                    <td>养老金比率</td>
                    <td>{{ scope.row.employee.salary.pensionPer }}</td>
                  </tr>
                  <tr>
                    <td>养老金基数</td>
                    <td>{{ scope.row.employee.salary.pensionBase }}</td>
                  </tr>
                  <tr>
                    <td>医疗保险比率</td>
                    <td>{{ scope.row.employee.salary.medicalPer }}</td>
                  </tr>
                  <tr>
                    <td>医疗保险基数</td>
                    <td>{{ scope.row.employee.salary.medicalBase }}</td>
                  </tr>
                  <tr>
                    <td>公积金比率</td>
                    <td>{{ scope.row.employee.salary.accumulationFundPer }}</td>
                  </tr>
                  <tr>
                    <td>公积金基数</td>
                    <td>
                      {{ scope.row.employee.salary.accumulationFundBase }}
                    </td>
                  </tr>
                  <tr>
                    <td>启用时间</td>
                    <td>{{ scope.row.employee.salary.createDate }}</td>
                  </tr>
                </table>
              </div>
              <el-tag>{{ scope.row.employee.salary.name }}</el-tag>
            </el-tooltip>
            <el-tag v-else>暂未设置</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="tot"
          label="总计(单位：元)"
          width="120"
          fixed="right"
        ></el-table-column>
      </el-table>
      <div style="display: flex; justify-content: flex-end">
        <el-pagination
          background
          @current-change="currentChange"
          @size-change="sizeChange"
          layout="sizes, prev, pager, next, jumper, ->, total, slot"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "SalMonth",
  data() {
    return {
      title: "",
      records: [],
      loading: false,
      total: 0,
      page: 1,
      size: 10,
      showDateSearchView: false,
      date: null,
      searchValue: {
        start: "",
        end: "",
        keyword: ""
      },
    };
  },
  mounted() {
    this.initRecords();
  },
  methods: {
    sizeChange(currentSize) {
      this.size = currentSize;
      this.initRecords();
    },
    currentChange(currentPage) {
      this.page = currentPage;
      this.initRecords();
    },
    initRecords() {
      this.loading = true;
      if (this.showDateSearchView && this.date != null) {
        this.searchValue.start = this.date[0];
        this.searchValue.end = this.date[1];
      } else {
          this.searchValue.start = "";
        this.searchValue.end = "";
      }
      let url = "/salary/sob/month/?page=" + this.page + "&size=" + this.size;
      url += "&workId=" + this.searchValue.keyword;
      url += "&start=" + this.searchValue.start;
      url += "&end=" + this.searchValue.end;
      this.getRequest(url).then((resp) => {
        this.loading = false;
        if (resp) {
          this.records = resp.data;
          this.total = resp.total;
        }
      });
    }
  },
  watch: {
      date: function(val) {
          if (val == null) {
              this.initRecords();
          }
      }
  }
};
</script>

<style>
/* 可以设置不同的进入和离开动画 */
/* 设置持续时间和动画函数 */
.slide-fade-enter-active {
  transition: all 0.8s ease;
}

.slide-fade-leave-active {
  transition: all 0.8s cubic-bezier(1, 0.5, 0.8, 1);
}

.slide-fade-enter, .slide-fade-leave-to
        /* .slide-fade-leave-active for below version 2.1.8 */ {
  transform: translateX(10px);
  opacity: 0;
}

.el-row {
  margin: 0;
  padding: 0;
}
</style>
